﻿'========================================================================
'功能:設備用途設定作業
'作者:shihyu
'日期: 2011/05/27
'========================================================================
Imports System.Data
Partial Class WebForm_SysParam_UseTypeMaintain
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            If Not ChkProgramRight(1) Then '查詢
                Me.btnQuery.Visible = False
            End If
            If Not ChkProgramRight(2) Then '新增
                Me.btnInsert.Visible = False
            End If
            If Not ChkProgramRight(3) Then '修改
                Me.gvUserType.Columns(0).Visible = False
            End If
        End If

    End Sub


    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        gvUserType.DataBind()
    End Sub


    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        Me.txtIDInsert.Text = ""
        Me.txtNameInsert.Text = ""
        Me.txtDescInsert.Text = ""
    End Sub
    Protected Function CheckIDExist() As Boolean

        If Me.txtIDInsert.Text = "" Then
            ShowMessageForAjax(btnISave, GetLocalResourceObject("IDEmpty"))
            Return False
        End If
        Dim bbl As AssetManage.BBL.UserTypeBBL = New AssetManage.BBL.UserTypeBBL()
        If bbl.UserTypeIsExist(dbName, Me.txtIDInsert.Text.Trim()) Then
            ShowMessageForAjax(btnISave, GetLocalResourceObject("UserTypeExist"))
            Me.txtIDInsert.Text = ""
            Me.txtIDInsert.Focus()
            Return False
        End If
        Return True
    End Function
    Protected Sub btnISave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnISave.Click

        If Me.CheckIDExist() = False Then
            Me.mpSearch.show()
            Return
        End If
        Me.dbUserType.Insert()
        Me.txtID.Text = ""
        Me.txtName.Text = ""
        Me.txtDesc.Text = ""
        Me.gvUserType.DataBind()
    End Sub
End Class
